mui.init();
var member_id = ws = spage = order_id = goods_id = '';
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	ws = plus.webview.currentWebview();
	spage = ws.spage; 
	order_id = ws.order_id;
	console.log(apiRoot + "?act=member_order&op=order_info&order_id="+order_id+'&member_id='+member_id);
	plus.nativeUI.showWaiting('加载中...');
	$.ajax({
		type:"get",
		url:apiRoot + "?act=member_order&op=order_info",
		data:{
			member_id:member_id,
			order_id:order_id
		}, 
		dataType:'json',
		success:function(data){
			console.log(JSON.stringify(data));
			if(data.code == 200){
				var html = '';
				if(data.datas.order_info){
//					$('.travel_time').text('日期：'+data.datas.order_info.travel_time);
//					$('.order_phone').text('联系方式：'+data.datas.order_info.reciver_phone);
//					$('.order_message').text(data.datas.order_info.order_message);
					switch(data.datas.order_info.order_state){
						case '10':                  //待付款
							$('.total').eq(0).css('display','block');
							$('.order_cancel').attr('data-order_id',data.datas.order_info.order_id);
							$('.payment').attr('data-order_id',data.datas.order_info.order_id);
						break;
						case '20':					//待出行
							$('.total').eq(1).css('display','block');
							$('.order_cancel').attr('data-order_id',data.datas.order_info.order_id);
							$('.order_complete').attr('data-order_id',data.datas.order_info.order_id);
						break;
						case '40':					//已完成
							$('.total').eq(2).css('display','block');
						break;
						case '0':					//已取消
							$('.total').eq(3).css('display','block');
						break;
						
					}
				} 
				$.each(data.datas.order_info.goods_list, function(k,v) {
					$('.mui-media-body b').text(v.goods_name); 
					$('.mui-media-body p').eq(0).text(v.goods_custom[1].value);
					$('.mui-media-body p').eq(1).text(v.goods_custom[2].value);
					$('.school_type').text(v.goods_custom[3].value); 
	//				$('.school_type').text(data.goods_info.goods_price); 
					$('.mui-media-object').attr('src', (v.image_url));			//图片 
					$('.price b').text('￥'+v.goods_detaile.goods_price);			//价格
					$('.price s').text('市场价：'+v.goods_detaile.goods_marketprice);    //市场价
					$('.detail p').text(v.goods_detaile.goods_jingle);
					$('.mobile').html(v.goods_detaile.mobile_body);  
					$('.mobile img').css('margin-right','4px');
					$('.order_amount').text(data.datas.order_info.order_amount); 
				});
				$('.mui-grid-9').html(html);
				plus.nativeUI.closeWaiting();	
				
			}else{
				plus.nativeUI.closeWaiting();	
				toast(data.datas.error);
			}
			
			//取消订单
			$('.order_cancel').on('click',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
				order_cancel(member_id,order_id,'Personal_diivingl.html');
			})
			//确认收货
			$('.order_complete').on('click',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
//				console.log(order_id);
				order_complete(member_id,order_id,'Personal_diivingl.html');
			})
			
			
			//付款
			$('.payment').on('click',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');   //订单id
				plus.nativeUI.actionSheet({cancel:"取消",buttons:[{title:"余额支付"},{title:"支付宝支付"},{title:"微信支付"}]},function(e){
					if(e.index == 1){
						$('.password-of-pay-wraper').css("display","block");
							$('#password_backdrop').css("display","block");
							$('.btn').slideUp()				
							
							//如果用户选择的是余额支付，则执行如下代码
							tool.shade(function (){
								$("#j_password_of_pay").hide();
							}).show();  
							//默认让第一个输入框获得焦点
							setTimeout(function (){
								$("#j_password_of_pay").show().find("input:password").eq(0).focus();
							},10); 
							var pwdInputs = $("#j_password_of_pay input:password");
							pwdInputs.each(function (index,item){
								$(this).on("keyup",function (){
									if(!tool.isEmpty($(this).val())){
										$(this).next().focus();
										//如果是最后一个输入框，则执行ajax操作
										if(index == pwdInputs.size() - 1){
											var pwd = "";
											$(this).blur();
											pwdInputs.each(function (){
												pwd += $(this).val();
											}); 
											yuezhifu(order_id,pwd);
			//									alert("用户输入的密码是："+ pwd +"，发送ajax，检查用户输入密码是否正确");	
			//									$("#j_password_of_pay").hide();
			//									tool.shade().hide();
			//									$('.popover').fadeOut();
										}
									}
								});
							});
					}else if(e.index == 2){
						ptype = 'alipay';
						payment(order_sn,goods_total);
					}else if(e.index == 3){
						ptype = 'wxpay';
						payment(order_sn,goods_total);
					}else{
						toast("取消支付");
					}
				});
				
			})

		},
		error:function(e){
			plus.nativeUI.closeWaiting();	
			error();
		}
	});
},false)
	
